﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>潜在客户列表管理</title>
    <!-- freemaker：引入模板文件，使用相对路径 来引用 ; .. 上一级目录views -->
    <#include "../common/link.ftl">

    <script>
        $(function () {
            // 新增/编辑按钮点击事件
            $(".btn-input").click(function () {
                $("#myModalLabel").html("潜在客户新增");
                $("#editForm input").val('');

                var data = $(this).data("json");
                if (data) {
                    $("#myModalLabel").html("潜在客户编辑");
                    $("#editForm input[name='id']").val(data.id);
                    // $("#editForm input[name=id]").val(data.id); 也可以。但是，一般有点的情况下，'job.id'，要加单引号，表示字符串
                    $("#editForm input[name='name']").val(data.name);
                    $("#editForm input[name='age']").val(data.age);
                    $("#editForm select[name='gender']").val(data.gender);
                    $("#editForm input[name='tel']").val(data.tel);
                    $("#editForm input[name='qq']").val(data.qq);
                    $("#editForm select[name='job.id']").val(data.jobId);
                    $("#editForm select[name='source.id']").val(data.sourceId);
                    $("#editForm select[name='seller.id']").val(data.sellerId);
                }
                // 打开模态框
                $("#myModal").modal('show');
            });

            /*  // 保存
              $(".btn-submit").click(function () {
                  // 使用 jQuery-form 插件来提交异步表单（有表单的时候）
                  $("#editForm").ajaxSubmit(/!*function (data) {
                      if(data.success){
                          $.messager.alert("标题：温馨提示", "msg：保存成功！2s后自动关闭。");
                          window.setTimeout(function () {
                              window.location.href = "/customer/potentialList.do";
                          },2000);
                      }else {
                          $.messager.popup(data.msg);
                      }
                  });*!/
              });*/

            // 表单数据验证
            $("#editForm").bootstrapValidator({
                feedbackIcons: {  // 图标
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                }, fields: {
                    tel: {
                        validators: {
                            noEmpty: {   // 不能为空
                                messages: "手机号必填"
                            },
                            stringLength: {
                                min: 11,
                                max: 11,
                                message: '请输入11位手机号码'
                            },
                            regexp: {  // 正则表达式验证
                                regexp: /^[1]([3-9])[0-9]{9}$/,
                                message: '不是真正的手机号码'
                            },
                            remote: {   // 远程验证
                                type: 'POST',
                                url: '/customer/checkTel.do',
                                data: {  // 传入后台
                                    id: $("#id").val()  // 从 id隐藏域取出
                                },
                                message: '该手机号码已经存在',
                                delay: 1000  // 过1s，发送过去
                            }
                        }
                    },
                    qq: {
                        validators: {
                            regexp: {  // 正则表达式验证
                                regexp: /^[1-9][0-9]{4,11}$/,
                                message: '不是真正的QQ'
                            }
                        }
                    }
                }
            })

            // -----------------------------------------------
            // 跟进按钮
            $('.btn-trace').click(function () {
                // 回显数据
                var json = $(this).data('json');  // json是客户对象 customer
                $('#traceForm input[name=name]').val(json.name);
                // 把客户id设置到跟进历史的对象的客户id中
                $("#traceForm input[name='customer.id']").val(json.id);

                $("#traceModal").modal('show');
            });

            // 跟进保存按钮
            $(".traceSubmit").click(function () {
                $("#traceForm").ajaxSubmit(handleMessage2);
            })

        // 使用日期插件
        $("input[name =traceTime]").datepicker({
            todayBtn: true,
            clearBtn: true,
            language: "zh-CN",
            autoclose: true,
            todayHighlight: true
        });
        // --------------------------------------------
        // 移交按钮
        $(".btn-transfer").click(function () {
            var json = $(this).data('json');  // json是客户对象
            $("#transferForm input[name='customer.name']").val(json.name);
            $("#transferForm input[name='customer.id']").val(json.id);
            $("#transferForm input[name='oldseller.name']").val(json.sellerName);  // 注意：模态框中的 oldseller 与 后台的 oldSeller（不是olderSeller）
            $("#transferForm input[name='oldseller.id']").val(json.sellerId);
            $("#transferModal").modal('show');
        })
        // 移交保存按钮
        $(".transferSubmit").click(function () {
            $("#transferForm").ajaxSubmit(handleMessage2);
        })

            // 不能使用，按钮不在表单内
            /*.on('success.form.bv', function(e){。。。}) 按钮修改为 submit */
            // 提交表单（异步提交）
            $(".btn-submit").click(function () {
                $("#editForm").ajaxSubmit(/*function (data) {
                    // 手动写配置，之前公共的 成功后是重新加载页面，现在提交成功不能重新加载
                    if(data.success) {
                        $.messager.alert("标题：温馨提示", "msg：保存成功！2s后自动关闭。")
                        window.setTimeout(function () {
                            // window.location.reload();
                            window.location.href = "/customer/potentialList.do";
                        }, 2000)
                    } else {
                        $.messager.popup(data.msg);
                    }
                })*/
                        handleMessage2)
            });
        });

    </script>

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <!-- 页面的头部内容回显 -->
    <#include "../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="customer_potential"/>
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>潜在客户管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/customer/potentialList.do" method="post">
                    <!-- 分页的隐藏域 当前页 -->
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}"
                               placeholder="请输入姓名/电话">
                    </div>
                    <div class="form-group">
                        <label for="seller"> 市场专员:</label>
                        <select class="form-control" id="sellerId" name="sellerId">
                            <option value="-1">全部</option>
                                <#list employees as e>
                                    <option value="${e.id}">${e.name}</option>
                                </#list>
                        </select>
                        <script>
                            $("#sellerId").val(${qo.sellerId!});
                        </script>
                    </div>
                    <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询
                    </button>
                    <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>名称</th>
                            <th>电话</th>
                            <th>QQ</th>
                            <th>职业</th>
                            <th>来源</th>
                            <th>销售员</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                            <#list result.list as customer>
                            <tr>
                                <!-- freemarker 如果取值时是空值 会报错 -->
                                <td>${customer_index + 1}</td>  <!-- 索引（从0开始）,注意：是_ 不是. -->
                                <td>${customer.name!}</td>
                                <td>${customer.tel!}</td>
                                <td>${customer.qq!}</td>
                                <td>${(customer.job.title)!}</td>
                                <td>${(customer.source.title)!}</td>
                                <td>${(customer.seller.name)!}</td>
                                <td>${customer.statusName!}</td>
                                <td>
                                <#-- 使用 data-* 属性来嵌入自定义数据，单引号 -->
                                    <a href="#"
                                       class="btn btn-info btn-xs btn-input" data-json='${customer.json}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    <a href="#"
                                       class="btn btn-success btn-xs btn-trace" data-json='${customer.json}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 跟进
                                    </a>
                                <#-- 管理员和经理才能看到该下拉框-->
                                <@shiro.hasAnyRoles name="admin,Market_Manager">
                                    <a href="#"
                                       class="btn btn-primary btn-xs btn-transfer" data-json='${customer.json}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 移交
                                    </a>
                                </@shiro.hasAnyRoles>
                                </td>
                            </tr>
                            </#list>
                    </table>
                    <!--分页-->
                    <#include "../common/page.ftl">
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>

<!-- Modal --><#--部门编辑模态框-->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">客户添加/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/customer/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">客户姓名：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="name"
                                   placeholder="请输入客户姓名">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="age" class="col-sm-3 control-label">客户年龄：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="age" name="age"
                                   placeholder="请输入客户年龄">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="gender" class="col-sm-3 control-label">客户性别：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="gender">
                                <option value="1">男</option>
                                <option value="0">女</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-3 control-label">客户电话：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="tel" name="tel"
                                   placeholder="请输入客户电话">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-3 control-label">客户QQ：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="qq" name="qq"
                                   placeholder="请输入客户QQ">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-3 control-label">客户工作：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="job.id">
                                <#list jobs as j>
                                    <option value="${j.id}">${j.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-3 control-label">客户来源：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="source.id">
                                <#list source as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-3 control-label">销售人员：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="seller.id">
                                <#list employees as e>
                                    <option value="${e.id}">${e.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div>
    </div>
</div>

<#--跟进历史-->
<div class="modal fade" id="traceModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">跟进</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/customerTraceHistory/saveOrUpdate.do" method="post" id="traceForm">
                    <input type="hidden" name="id" id="customerTransferId"/>
                <#-- 跟进类型，就是潜在客户（售前跟进0）-->
                    <input type="hidden" name="type" value="0">
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">客户姓名：</label>
                        <div class="col-lg-6">
                        <#--新增,新增跟进历史没有ID,客户应该要有ID,不然就不知道当前是哪个客户的跟进历史-->
                            <input type="hidden" name="customer.id"/>
                            <input type="text" class="form-control" readonly name="name"/>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">跟进时间：</label>
                        <div class="col-lg-6 ">
                            <input type="text" class="form-control "  name="traceTime" placeholder="请输入跟进时间">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">跟进记录：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="traceDetails"
                                   placeholder="请输入跟进记录"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">交流方式：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="traceType.id">
                                <#list communicationMethods as c>
                                    <option value="${c.id}">${c.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">跟进结果：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="traceResult">
                                <option value="3">优</option>
                                <option value="2">中</option>
                                <option value="1">差</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">备注：</label>
                        <div class="col-lg-6">
                            <textarea type="text" class="form-control" name="remark"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary traceSubmit">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<#--移交模态框-->
<div id="transferModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/customerTransfer/saveOrUpdate.do" method="post" id="transferForm" style="margin: -3px 118px">
                    <input type="hidden" name="id" id="customerTransferId"/>
                    <div class="form-group" >
                        <label for="name" class="col-sm-4 control-label">客户姓名：</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control"  name="customer.name"   readonly >
                            <input type="hidden" class="form-control"  name="customer.id"  >
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">旧营销人员：</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control"  name="oldseller.name" readonly >
                            <input type="hidden" class="form-control"  name="oldseller.id"  >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">新营销人员：</label>
                        <div class="col-sm-8">
                            <select name="newseller.id" id="newseller" class="form-control">
                                <#list employees as e>
                                    <option value="${e.id}">${e.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">移交原因：</label>
                        <div class="col-sm-8">
                            <textarea type="text" class="form-control" id="reason" name="reason" cols="10" ></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary transferSubmit" >保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

</body>
</html>
